#pragma once

#include <engine.core/noncopyable.hpp>
#include <engine.core/factory.hpp>

#include "exports.hpp"
#include "Item.hpp"




class ENGINE_DATABASE_API DatabaseSystem;




/**
 * The IDatabaseReader defines the interface any reader is required to implement,
 * in order to read all DatabaseItems from a specific source.
 */
class ENGINE_DATABASE_API DatabaseReader : public noncopyable
{
public:

	typedef DatabaseItem::Properties                        Properties;

	// The defined functor must take two arguments: the name of the item and a data array
	typedef boost::function<LOOSE_PTR(DatabaseItem)(const Properties&)>   ItemFunctor;
	typedef factory<QString,LOOSE_PTR(DatabaseItem), ItemFunctor>         ItemFactory;

public:

	DatabaseReader() {}
	virtual ~DatabaseReader() {}



	/**
	 * When implemented, this function should simply read the next
	 * item from the source, or return an empty DatabaseItemPtr to
	 * indicate that the reader is finished.
	 *
	 * exceptions of type critical_exceptions can be thrown to abort the loading
	 * process, all other exceptions are caught, and loading continues with the next
	 * item.
	 */
	virtual LOOSE_PTR(DatabaseItem) read() = 0;
};
///////////////////////////////////////////////////////////////////////////////////////////////////

DEFINE_STRICT_PTR(DatabaseReader);
